package eu.jpereira.trainings.designpatterns.creational.builder;

import java.util.Iterator;


import eu.jpereira.trainings.designpatterns.creational.builder.model.Report;
import eu.jpereira.trainings.designpatterns.creational.builder.model.SaleEntry;
import eu.jpereira.trainings.designpatterns.creational.builder.model.SoldItem;

public class HTMLReportAssembler implements ReportAssembler {
        Report report;
        private SaleEntry saleEntry;

       

        public void setSaleEntry(SaleEntry saleEntry)
        {
                this.saleEntry = saleEntry;
        }
       
        @Override
        public void makeReport()
        {              
                report = new Report();

                HTMLReportBody reportBody = new HTMLReportBody();
                reportBody.putContent("<span class=\"customerName\">");
                reportBody.putContent(this.saleEntry.getCustomer().getName());
                reportBody.putContent("</span><span class=\"customerPhone\">");
                reportBody.putContent(this.saleEntry.getCustomer().getPhone());
                reportBody.putContent("</span>");
               
                reportBody.putContent("<items>");
               
                Iterator<SoldItem> it = saleEntry.getSoldItems().iterator();
                while ( it.hasNext() ) {
                        SoldItem soldEntry= it.next();
                        reportBody.putContent("<item><name>");
                        reportBody.putContent(soldEntry.getName());
                        reportBody.putContent("</name><quantity>");
                        reportBody.putContent(soldEntry.getQuantity());
                        reportBody.putContent("</quantity><price>");
                        reportBody.putContent(soldEntry.getUnitPrice());
                        reportBody.putContent("</price></item>");
                }
                reportBody.putContent("</items>");
                report.setReportBody(reportBody);
       

        }
       
        public Report getReport()
        {
                return report;
        }

}
